package com.iflytek.cosmo.ocr.web.controller;

import com.iflytek.cosmo.ocr.common.config.ArgusProperties;
import com.iflytek.cosmo.ocr.common.util.IpAddress;
import com.iflytek.cosmo.ocr.service.ArgusPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Api(value = "客户端API", tags = "安装与启动")
@RestController
@RequestMapping("/client")
public class ClientSAIController {
	private static final Logger logger = LoggerFactory.getLogger(ClientSAIController.class);
	
	@Autowired
	ArgusProperties argusProperties;
	
	@Autowired
	ArgusPostService argusPostService;
	
	
	@ApiOperation(value = "客户端安装", notes = "客户端安装", httpMethod = "POST")
	@RequestMapping(value = "/install", method = RequestMethod.POST)
	public void clientInstall(HttpServletRequest request, @RequestBody String macAddress) {
		String ip = IpAddress.getRemoteIpAddr(request);
		if (argusProperties.getBuryingEnable()) {
             argusPostService.postAgent(ip, argusProperties.getOcrInstallNum(), 1, "macAd=" + macAddress, null);
        }
	}
	
	@ApiOperation(value = "客户端启动", notes = "客户端启动", httpMethod = "POST")
	@RequestMapping(value = "/startUp", method = RequestMethod.POST)
	public void clientStart(HttpServletRequest request, @RequestBody String macAddress) {
		String ip = IpAddress.getRemoteIpAddr(request);
		if (argusProperties.getBuryingEnable()) {
            argusPostService.postAgent(ip, argusProperties.getOcrStartUpNum(), 1, "macAd=" + macAddress, null);
        }
	}
}
